<style lang="less">
@import "./login.less";
</style>
<template>
<div class="login" width="100%" height="1000px">
    <div class="login-con">
        <Card :bordered="false">
            <p slot="title">
                <Icon type="log-in"></Icon>
                欢迎登录 
            </p>
            <div class="form-con">
                <Form ref="formInline" :model="formInline" :rules="ruleInline" inline>
                    <FormItem prop="name">
                        <Input type="text" v-model="formInline.name" placeholder="用户名">
                            <Icon type="ios-person-outline" slot="prepend"></Icon>
                        </Input>
                    </FormItem>

                    <FormItem prop="password">
                        <Input type="password" v-model="formInline.password" placeholder="密码">
                            <Icon type="ios-locked-outline" slot="prepend"></Icon>
                        </Input>
                    </FormItem>
                    <FormItem>
                        <Button type="primary" @click="handleSubmit('formInline')">登录</Button>
                    </FormItem>
                </Form>
            </div>
        </Card>
    </div>
</div>
</template>

<script>
import util from "../libs/util";
export default {
  data() {
    return {
      formInline: {
        name: "",
        password: ""
      },
      ruleInline: {
        name: [{ required: true, message: "请输入用户名！", trigger: "blur" }],
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
          {
            type: "string",
            min: 6,
            message: "密码长度最小为6",
            trigger: "blur"
          }
        ]
      }
    };
  },
  methods: {
    handleSubmit(name) {
      var formValue = this.formInline;
      this.$http
        .post(util.baseURL + "admin/login", formValue, { emulateJSON: true })
        .then(
          response => {
            if (response.data.data) {
              // 存储信息和token
              sessionStorage.setItem("admin", response.data.data.name);
              this.$router.push("/index");
            } else {
              this.$Message.error(response.data.msg);
            }
          },
          error => {
            this.$Message.error("没有链接网络");
          }
        );
      /**
  var params = {
                    data : formValue,
                    url : "admin/login",
                    sCallback : function(data) {
                        console.log(data);
                        if(data) {
                                // 存储信息和token
                            //sessionStorage.setItem("admin", response.data.data);
                           // this.$router.push('/index');
                        } else {
                           // this.$Message.error(response.data.msg);
                        }
                    }
                };
                util.request(params);
*/
    }
  }
};
</script>
